﻿using System;
using System.Net.Http;
using Newtonsoft.Json;
using System.Text;

namespace _12_AI
{
    class Deepseek
    {
        public static string answer="";
        public static async void Deepseek_API(string question)
        {
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("Authorization", $"Bearer sk-d634f7fbdac64175b80fc8465a761744");
            var requestData = new
            {
                model = "deepseek-chat",//DeepSeek-V3
                messages = new[]
                {
                    new{
                            role= "user" ,
                            content=question
                        }
                    }
            };//请求参数

            var jsonContent = JsonConvert.SerializeObject(requestData);//转换成json格式
            var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
            var response = await client.PostAsync($"https://api.deepseek.com/chat/completions", content);
            Console.WriteLine(content);
            Console.WriteLine(jsonContent);
            var responseContet = await response.Content.ReadAsStringAsync();

            dynamic result = JsonConvert.DeserializeObject(responseContet);
            answer = result.choices[0].message.content;
        }
    }
}
